﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_BEGINNER_TO_PROFICIENT.DesignPatterns.CreationMode.SingletonPattern
{
    // 懒汉式线程安全
    public class SingleObjectLazySafe
    {
        private static readonly Lazy<SingleObjectLazySafe> _lazyInstance = new Lazy<SingleObjectLazySafe>(() => new SingleObjectLazySafe());

        private SingleObjectLazySafe() { }

        public static SingleObjectLazySafe GetInstance()
        {
            return _lazyInstance.Value;
        }

        public void ShowMessage()
        {
            Console.WriteLine("Hello World");
        }

        public static void Execute()
        {
            SingleObjectHungry ob = SingleObjectHungry.GetInstance();
            ob.ShowMessage();
        }
    }
}
